﻿Public Class MTRGT

    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection
    Dim PROVIDER_Check As New PROVIDERSCLASS

    Private Sub MTRGT_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        queryMTRGTGrid()

        DesignForm(Me)
        DesignGrid(MASMTYPERGTGrid)

        PROVIDER_Check.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub queryMTRGTGrid()
        Dim objSelectDataMastypergt As New mastypergt

        Dim masmtypergtData As DataTable
        masmtypergtData = connect.GetTable(objSelectDataMastypergt.selectMasmtypergt_)
        'masgrpdrgData = connectlocal.GetTable(objSelectDataMasgrpdrg.selectMasgrpdrg_)
        MASMTYPERGTGrid.PrimaryGrid.DataSource = masmtypergtData
    End Sub

    Private Sub MASMTYPERGTGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles MASMTYPERGTGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        'f.TXT_CID.Text = grid.Cells.Item(2).Value
        MTRGTIDTxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ID หมวด").Value()
        MTRGTNAMETxt.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("ชื่อหมวดคู่สัญญา").Value()

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการมีรายการย่อย").Value() = True Then
            masmtypergtSDETChk.Checked = True
        Else
            masmtypergtSDETChk.Checked = False
        End If

        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            masmtypergtStatusChk.Checked = True
        Else
            masmtypergtStatusChk.Checked = False
        End If

        Dim objChkboxUpdate As New CLICKGRIDCHECKBOX
        objChkboxUpdate.clickChkboxUpdate("masmtypergt", CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการมีรายการย่อย").Value(), "sdet", "mtrgtid", MTRGTIDTxt.Text)
        objChkboxUpdate.clickChkboxUpdate("masmtypergt", CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value(), "status", "mtrgtid", MTRGTIDTxt.Text)
    End Sub

    Private Sub addMasmtypergt_Click(sender As Object, e As EventArgs) Handles addMasmtypergt.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PADD_ = True Then
                If MTRGTNAMETxt.Text.ToString.Length > 0 Then
                    Dim objInsertData As New mastypergt
                    objInsertData.MTRGTNAME_ = MTRGTNAMETxt.Text
                    objInsertData.SDET_ = masmtypergtSDETChk.Checked
                    objInsertData.STATUS_ = masmtypergtStatusChk.Checked
                    objInsertData.insertMasmtypergtData()

                    Dim objSelectDataMastypergt As New mastypergt
                    Dim masmtypergtData As DataTable
                    masmtypergtData = connect.GetTable(objSelectDataMastypergt.selectMasmtypergt_)
                    'masgrpdrgData = connectlocal.GetTable(objSelectDataMasgrpdrg.selectMasgrpdrg_)
                    MASMTYPERGTGrid.PrimaryGrid.DataSource = masmtypergtData

                    'objSelectDataMastypergt.masmtypergtCmb(masmtypergtMasstypergtCmb)

                    MTRGTIDTxt.Text = ""
                    MTRGTNAMETxt.Text = ""
                    masmtypergtSDETChk.Checked = False
                    masmtypergtStatusChk.Checked = False
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editMasmtypergt_Click(sender As Object, e As EventArgs) Handles editMasmtypergt.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_Check.PUPD_ = True Then
                If MTRGTIDTxt.Text.ToString.Length > 0 And MTRGTNAMETxt.Text.ToString.Length > 0 Then
                    Dim editStat As Integer
                    editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลหมวดคู่สัญญาดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                    If editStat = 1 Then
                        Dim objEditData As New mastypergt
                        objEditData.MTRGTID_ = MTRGTIDTxt.Text
                        objEditData.MTRGTNAME_ = MTRGTNAMETxt.Text
                        objEditData.SDET_ = masmtypergtSDETChk.Checked
                        objEditData.STATUS_ = masmtypergtStatusChk.Checked
                        objEditData.editMasmtypergtData()

                        Dim objSelectDataMastypergt As New mastypergt
                        Dim masmtypergtData As DataTable
                        masmtypergtData = connect.GetTable(objSelectDataMastypergt.selectMasmtypergt_)
                        'masgrpdrgData = connectlocal.GetTable(objSelectDataMasgrpdrg.selectMasgrpdrg_)
                        MASMTYPERGTGrid.PrimaryGrid.DataSource = masmtypergtData

                        'objSelectDataMastypergt.masmtypergtCmb(masmtypergtMasstypergtCmb)

                        MTRGTIDTxt.Text = ""
                        MTRGTNAMETxt.Text = ""
                        masmtypergtSDETChk.Checked = False
                        masmtypergtStatusChk.Checked = False
                    End If
                Else
                    MsgBox("โปรดระบุข้อมูลให้ครบถ้วน")
                End If
            Else
                MsgBox(PROVIDER_Check.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL("masmtypergt")
        nextform.ShowDialog()
    End Sub

    Private Sub ButtonItem1_Click(sender As Object, e As EventArgs) Handles ButtonItem1.Click
        Dim nextform As New IMPORTEXCEL("masmtypergt")
        nextform.ShowDialog()
    End Sub

End Class